import os
with open("a.txt",mode="r",encoding="utf-8") as f1,\
      open("c.txt",mode="w",encoding="utf-8") as f2:
    for line in f1 :
        if "1" in line:
            line = line.replace("1","哈哈哈")
    f2.write(line)
os.remove("a.txt")
os.rename("c.txt","a.txt")





